package com.orangelife.mobile.washcar.activity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.common.sp.UserSp;
import com.curry.android.http.OrangeErrorHandler;
import com.curry.android.http.VolleyHttpUtil;
import com.curry.android.util.DecimalUtil;
import com.curry.android.util.DialogHelper;
import com.curry.android.util.IntentHelper;
import com.curry.android.util.JSONHelper;
import com.curry.android.util.MoneyUtil;
import com.curry.android.util.StringUtil;
import com.curry.android.util.ToastHelper;
import com.curry.orangelife.mobile.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.orangelife.mobile.common.activity.OrangeLifeBaseActivity;
import com.common.jump.JumpManager;
import com.orangelife.mobile.common.view.ConfirmDialog;
import com.orangelife.mobile.common.view.EmptyLayout;
import com.orangelife.mobile.constants.Constant;
import com.orangelife.mobile.point.biz.MyPointBiz;
import com.orangelife.mobile.voucher.biz.VoucherBiz;
import com.orangelife.mobile.voucher.biz.VoucherHttpBiz;
import com.orangelife.mobile.pay.activity.UsersPaidActivity;
import com.orangelife.mobile.pay.biz.PaymentModule;
import com.orangelife.mobile.main.biz.JumpUtil;
import com.orangelife.mobile.voucher.biz.SelectedVoucherIDListHelper;
import com.orangelife.mobile.washcar.biz.WashCarBiz;
import com.orangelife.mobile.washcar.entity.WashCarChooseEntity;
import com.thirdsdk.qiniu.QiniuHelper;

import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 上门洗车
 * Created by ${shz} on 2016/1/14.
 */
public class WashCarActivity extends OrangeLifeBaseActivity {
    @Bind(R.id.ib_title_left)
    LinearLayout ibTitleLeft;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_username)
    TextView tvUserName;
    @Bind(R.id.tv_userphone)
    TextView tvUserPhone;
    @Bind(R.id.tv_address)
    TextView tvAddress;
    @Bind(R.id.tv_one)
    TextView tvOne;
    @Bind(R.id.ll_addressManage)
    LinearLayout llAddressManage;
    @Bind(R.id.rl_title)
    RelativeLayout rlTitle;
    @Bind(R.id.ivNormal)
    ImageView ivNormal;
    @Bind(R.id.tvNormalPrice)
    TextView tvNormalPrice;
    @Bind(R.id.ivNormalCheck)
    ImageView ivNormalCheck;
    @Bind(R.id.ivDelicate)
    ImageView ivDelicate;
    @Bind(R.id.tvDelicatePrice)
    TextView tvDelicatePrice;
    @Bind(R.id.ivDelicateCheck)
    ImageView ivDelicateCheck;
    @Bind(R.id.llVoucher)
    LinearLayout llVoucher;
    @Bind(R.id.tvHint)
    TextView tvHint;
    @Bind(R.id.ivHint)
    ImageView ivHint;
    @Bind(R.id.tvTip)
    TextView tvTip;
    @Bind(R.id.ivChoose)
    ImageView ivChoose;
    @Bind(R.id.rlCleanInterior)
    RelativeLayout rlCleanInterior;
    @Bind(R.id.etNote)
    RelativeLayout etNote;
    @Bind(R.id.tvTotal)
    TextView tvTotal;
    @Bind(R.id.tvPropertyNum)
    TextView tvPropertyNum;
    @Bind(R.id.tvYuan)
    TextView tvYuan;
    @Bind(R.id.btPayCost)
    Button btPayCost;
    @Bind(R.id.rlNormal)
    LinearLayout rlNormal;
    @Bind(R.id.rlDelicate)
    LinearLayout rlDelicate;
    @Bind(R.id.tvVoucherInfo)
    TextView tvVoucherInfo;
    @Bind(R.id.tvNormalName)
    TextView tvNormalName;
    @Bind(R.id.tvDelicateName)
    TextView tvDelicateName;
    @Bind(R.id.ivSwitch)
    ImageView ivSwitch;
    @Bind(R.id.tvPoint)
    TextView tvPoint;
    @Bind(R.id.zeng)
    TextView zeng;
    @Bind(R.id.tvJifenTip)
    TextView tvJifenTip;
    @Bind(R.id.ib_addresslist)
    ImageView ibAddresslist;
    @Bind(R.id.ll_addresslist)
    LinearLayout llAddresslist;
    @Bind(R.id.emptyLayout)
    EmptyLayout emptyLayout;
    @Bind(R.id.llClick)
    LinearLayout llClick;
    @Bind(R.id.llNoDataTip)
    LinearLayout llNoDataTip;
    @Bind(R.id.tvRemark)
    TextView tvRemark;

    private boolean blChoose = true;
    private Dialog dialog;
    /**
     * 普通洗车的价钱
     */
    private String NormalPrice;
    private String NormalID;
    private String NormalImgs;
    private String normalMerID;
    /**
     * 精致洗车的价钱
     */
    private String DelicatePrice;
    private String DelicateID;
    private String DelicateImgs;
    private String delicateMerID;
    /**
     * 洗车规格的id
     */
    private String mCurrentProductID;
    private String mMerID;
    /**
     * 洗车类型
     */
    private String mWashType = "0";
    /**
     * 第一个选项卡状态
     */
    private String one_washType;
    /**
     * 第二个选项卡状态
     */
    private String two_washType;
    /**
     * 是否清理内部1是 0否
     */
    private String washInner = "0";


    /**
     * 抵用卷id
     */
    private String voucherID = "";
    /**
     * 经纬度
     */
    private String addrLng;
    private String addrLat;
    private String remark;
    public static final int NETWORK_ERROR = 1; // 网络错误
    public static final int NETWORK_LOADING = 2; // 加载中
    public static final int NODATA = 3; // 没有数据
    private int currentReqMode = NETWORK_LOADING;
    private List<WashCarChooseEntity> mWashCarProductList;
    private String voucherInfo = VoucherBiz.STR_NO_VOUCHER;

    private boolean hasWashCarService = false;

    private String msgNoService = "该小区尚未开通此服务，敬请期待";

    private boolean ivSwitchSelected = false;
    private int isDeduction = 0;
    private String points = "0";
    private String pRuleID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wash_car);
        ButterKnife.bind(this);
        requestWashCarChoose();
        initView();
        initUserInfo();
        setListener();
        showDataDialog();
    }

    /**
     * 初始化界面
     */
    private void initView() {
        tvTitle.setText("上门洗车");
        tvOne.setText("服务说明");
        tvOne.setTextColor(getResources().getColor(R.color.lightOrange));
        emptyLayout.setOnLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                currentReqMode = NETWORK_LOADING;
                requestWashCarChoose();
            }
        });
    }

    private void initUserInfo() {
        String name = UserSp.getNickname();
        String phone = UserSp.getRegPhone();
        tvUserName.setText(name);
        tvUserPhone.setText(phone);
    }

    private void showDataDialog() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
        Date date = new Date(System.currentTimeMillis());
        int time = Integer.parseInt(simpleDateFormat.format(date));
        if (time >= 18 || time < 8) {
            final ConfirmDialog dialog = new ConfirmDialog(this, "提示", "洗车服务时间为08:00--18:00，现在下单我们将在服务时间内安排师傅与您联系预约洗车。", "确定", null);
            dialog.show();
            dialog.setClicklistener(new ConfirmDialog.ClickListenerInterface() {
                @Override
                public void doLeft() {
                    dialog.dismiss();
                }

                @Override
                public void doRight() {
                }
            });
        }
    }

    /**
     * 选择是否清洗车内饰
     */
    private void selectWashInner() {
        if (blChoose || mWashType.equals("1")) {
            washInner = "1";
            blChoose = false;
            ivChoose.setBackgroundResource(R.drawable.icon_selected);
        } else {
            washInner = "0";
            blChoose = true;
            ivChoose.setBackgroundResource(R.drawable.icon_unselected_grey);
        }
    }

    /**
     * 选择洗车类型
     *
     * @param washCarType 洗车类型
     */
    private void selectWashCarType(int washCarType) {
        if (washCarType == 0) {
            rlNormal.setBackgroundResource(R.drawable.shape_btn_orange_check);
            rlDelicate.setBackgroundResource(R.drawable.shape_btn_orange_uncheck);
            ivNormalCheck.setBackgroundResource(R.drawable.icon_selected);
            ivDelicateCheck.setBackgroundResource(R.drawable.icon_unselected_grey);
            mCurrentProductID = NormalID;
            mMerID = normalMerID;
            //这里需要设置传入接口的洗车金额
            mCurrentGoodsPrice = NormalPrice;
            idWashInner(one_washType);
        } else {
            rlNormal.setBackgroundResource(R.drawable.shape_btn_orange_uncheck);
            rlDelicate.setBackgroundResource(R.drawable.shape_btn_orange_check);
            ivNormalCheck.setBackgroundResource(R.drawable.icon_unselected_grey);
            ivDelicateCheck.setBackgroundResource(R.drawable.icon_selected);
            mCurrentProductID = DelicateID;
            mMerID = delicateMerID;
            // 这里需要设置传入接口的洗车金额
            mCurrentGoodsPrice = DelicatePrice;
            idWashInner(two_washType);
        }
        selectWash = washCarType;
        requestPoints(washCarType);
        voucherID = "";/*重置抵用券ID*/
        if (StringUtil.isBlank(mCurrentGoodsPrice)) {
            mCurrentGoodsPrice = "0.00";
        }
        mTotalCost = mCurrentGoodsPrice;
    }

    /**
     * 添加dd洗车订单
     */
    private void requestAddWashCarOrder() {
        String address = tvAddress.getText().toString();
        if (StringUtil.isBlank(address)) {
            ToastHelper.getInstance()._toast("请选择洗车地址");
            return;
        } else if (!hasSelectedOneWashType()) {
            return;
        }
        dialog = DialogHelper.getInstance().createLoadingDialog(WashCarActivity.this);
        dialog.show();
        String name = tvUserName.getText().toString();
        String phone = tvUserPhone.getText().toString();

        List<Map<String, Object>> orderDetails = new ArrayList<>();
        Map<String, Object> orderDetailsMap = new HashMap<>();
        orderDetailsMap.put("goodsID", mCurrentProductID);
        orderDetails.add(orderDetailsMap);
        List<String> vouchers = new ArrayList<>();
        vouchers.add(voucherID);
        HashMap<String, Object> map = new HashMap<>();
        map.put("shipName", name);
        map.put("shipAddr", address);
        map.put("shipPhone", phone);
        map.put("addrLng", addrLng);
        map.put("addrLat", addrLat);
        map.put("usePoints", isDeduction);//是否使用积分
        map.put("goodsCost", mCurrentGoodsPrice);
        map.put("totalCost", mTotalCost);
        map.put("orderDetails", orderDetails);
        if (!voucherID.equals("")) {
            map.put("vouchers", vouchers);
        }
        map.put("washType", mWashType);
        map.put("remark", remark);
        map.put("washInner", washInner);

        WashCarBiz.getInstance().addWashCarOrder(map, new VolleyHttpUtil.ResponseCallBack() {
            @Override
            public void handleResponse(JSONObject response, int errCode) {
                dismissProgress();
                handleAddWashCarOrder(response);
            }
        });
    }


    private void handleAddWashCarOrder(JSONObject response) {
        if (OrangeErrorHandler.getInstance().isSuccess(response)) {
            DialogHelper.closeDialog(dialog);
            Map<String, Object> entity = (Map<String, Object>) JSONHelper.jsonToMap(
                    response.toString()).get("entity");
            Map<String, Object> crePay = (Map<String, Object>) entity.get("crePay");
            String totalCost = String.valueOf(crePay.get("totalCost"));
            String couponCost = String.valueOf(crePay.get("couponCost"));
            String outtradeno = String.valueOf(crePay.get("outtradeno"));
            String orderContent = String.valueOf(crePay.get("orderContent"));
            String points = String.valueOf(crePay.get("points"));
            String orderType = String.valueOf(crePay.get("orderType"));
            jumpToPay(couponCost, outtradeno, orderContent, points, orderType);
        }
    }

    /**
     * 判断是否已经选择洗车规格
     */
    private boolean hasSelectedOneWashType() {
        if (StringUtil.isBlank(mCurrentProductID)) {
            ToastHelper.getInstance()._toast("请选择洗车的规格");
            return false;
        }
        return true;
    }

    private void idWashInner(String washType) {
        if (washType == null || washType.equals("")) {
            return;
        }
        if (washType.equals("0")) {
            washInner = "0";
            blChoose = true;
            ivChoose.setBackgroundResource(R.drawable.icon_unselected_grey);
        } else if (washType.equals("1")) {
            washInner = "1";
            blChoose = false;
            ivChoose.setBackgroundResource(R.drawable.icon_selected);
        }
        mWashType = washType;
    }

    /**
     * 请求洗车的规格列表
     */
    private void requestWashCarChoose() {
        currentReqMode = NETWORK_LOADING;
        showProgress();
        if (!isConnected(false)) {
            emptyLayout.setErrorType(EmptyLayout.NETWORK_ERROR);
            return;
        }
        llNoDataTip.setVisibility(View.VISIBLE);
        HashMap<String, String> map = new HashMap<>();
        WashCarBiz.getInstance().getWashCarChoose(map, new VolleyHttpUtil.ResponseCallBack() {
            @Override
            public void handleResponse(JSONObject response, int errCode) {
                dismissProgress();
                mWashCarProductList = WashCarBiz.handleWashCarChoose(response, errCode);
                if (mWashCarProductList != null) {
                    if (mWashCarProductList.size() == 0) {
                        hasWashCarService = false;
                        resetPrice();
                        emptyLayout.setErrorMessage("该小区尚未开通此服务，敬请期待");
                        emptyLayout.setErrorType(EmptyLayout.NODATA);
                    } else {
                        hasWashCarService = true;
                        updatePrice();
                    }
                }
            }
        });
    }

    private void resetPrice() {
        DelicatePrice = "0.00";
        NormalPrice = "0.00";
    }

    private void updatePrice() {
        for (int i = 0; i < mWashCarProductList.size(); i++) { //washType
            WashCarChooseEntity wcce = mWashCarProductList.get(i);
            String goodsName = String.valueOf(wcce.getGoodsName());
            if (i == 0) {
                one_washType = String.valueOf(wcce.getStore());
                tvNormalName.setText(goodsName);
                NormalID = String.valueOf(wcce.getGoodsID());
                NormalPrice = MoneyUtil.handleMoney(String.valueOf(wcce.getPrice()));
                NormalImgs = String.valueOf(wcce.getGoodsLogo());
                normalMerID = String.valueOf(wcce.getMerID());
            } else {
                two_washType = String.valueOf(wcce.getStore());
                tvDelicateName.setText(goodsName);
                DelicateID = String.valueOf(wcce.getGoodsID());
                delicateMerID = String.valueOf(wcce.getMerID());
                DelicatePrice = MoneyUtil.handleMoney(String.valueOf(wcce.getPrice()));
                DelicateImgs = String.valueOf(wcce.getGoodsLogo());
            }
        }
        tvNormalPrice.setText(Constant.RMB_FLAG + NormalPrice);
        ImageLoader.getInstance().displayImage(QiniuHelper.getUrlWithSmallQiniuImage(NormalImgs), ivNormal);
        tvDelicatePrice.setText(Constant.RMB_FLAG + DelicatePrice);
        ImageLoader.getInstance().displayImage(QiniuHelper.getUrlWithSmallQiniuImage(DelicateImgs), ivDelicate);
    }

    private void requestVoucherHighestPrice() {
        showDialog(this);
        if (hasSelectedOneWashType()) {
            VoucherHttpBiz.getVoucherHighestPriceListWithGood(mMerID, mCurrentProductID, mTotalCost, VoucherHttpBiz.TYPE_WASH_CAR, new VolleyHttpUtil.ResponseCallBack() {
                @Override
                public void handleResponse(JSONObject response, int errCode) {
                    closeDialog();
                    List<Map<String, Object>> highestPriceVoucherList = VoucherHttpBiz.handleVoucherHighestPriceList(response);
                    if (highestPriceVoucherList != null && highestPriceVoucherList.size() > 0) {
                        voucherPrice = String.valueOf(highestPriceVoucherList.get(0).get("money"));
                        voucherPrice = MoneyUtil.handleMoney(voucherPrice);
                        updateTotalPrice();
                        if (!StringUtil.isBlank(voucherPrice)) {/*默认是暂无，而暂无也点不进去，所以不需要处理无值的情况*/
                            voucherInfo = voucherPrice + "元抵用券";
                        }
                        VoucherBiz.setVoucherInfoBackground(tvVoucherInfo, voucherInfo, WashCarActivity.this);
                        voucherID = String.valueOf(highestPriceVoucherList.get(0).get("couponID"));
                        SelectedVoucherIDListHelper.getInstance().addSelectedVoucherID(voucherID, mCurrentProductID, true);
                    }
                }
            });
        }
    }


    private void jumpToIntroduction() {
        JumpUtil.jumpActivity(WashCarActivity.this, "http://www.sdh2o.net/introduce/intro_washcar.html" + "?title=服务说明");
    }

    private void jumpToPay(String couponCost, String outtradeno, String orderContent, String points, String orderType) {
        Bundle bundle = new Bundle();
        bundle.putString("totalCost", mTotalCost);
        bundle.putString("totalPrice", Constant.RMB_FLAG + mTotalCost);
        bundle.putString("couponCost", couponCost);
        bundle.putString("outtradeno", outtradeno);
        bundle.putString("orderInfo", orderContent);
        bundle.putString("points", points);
        bundle.putString(PaymentModule.PAID_METHOD, PaymentModule.mode[11]);
        bundle.putString("orderType", orderType);
        IntentHelper.getInstances().bundleWithExtra(WashCarActivity.this, UsersPaidActivity.class, bundle);
    }

    private void jumpToAddress() {
        //JumpManager.jumpToAddress();
        Bundle bundle1 = new Bundle();
        IntentHelper.getInstances().bundleWithBundleForResult(WashCarActivity.this, ChooseAddressActivity.class, bundle1, 1);
    }

    private void jumpToRemark() {
        Bundle bundle2 = new Bundle();
        String note = tvRemark.getText().toString();
        bundle2.putString("remark", note);
        IntentHelper.getInstances().bundleWithBundleForResult(WashCarActivity.this, WashCarRemarkActivity.class, bundle2, 1);
    }

    /**
     * 跳转到抵用券列表
     */
    private void jumpToVoucherList() {
        if (hasSelectedOneWashType() && VoucherBiz.hasVoucher(voucherInfo, true)) {
            VoucherHttpBiz.cancelVoucherHighestPriceList();/*为了避免进入抵用券列表，选中抵用券后，原先最高金额抵用券的值才返回来的情况出现，如果超时没回来，就取消请求*/
            SelectedVoucherIDListHelper.getInstance().setVoucherListMapKey(mCurrentProductID);
            JumpManager.jumpToVoucherListWithGood(this, VoucherHttpBiz.TYPE_WASH_CAR, mMerID, mCurrentProductID, mTotalCost);
        }
    }

    @SuppressLint("ResourceAsColor")
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            Bundle bundle = data.getExtras();
            if (resultCode == JumpManager.RESULT_CODE_VOUCHER_LIST) {
                handleJumpBackVoucher();
            } else if (resultCode == JumpManager.RESULT_CODE_ADDRESS) {
                handleJumpBackAddress(bundle);
            } else if (resultCode == JumpManager.RESULT_CODE_REMARK) {
                handleJumpBackRemark(bundle);
            }
        }
    }

    private void handleJumpBackAddress(Bundle bundle) {
        if (bundle == null) {
            return;
        }
        addrLng = String.valueOf(bundle.get("addrLng"));
        addrLat = String.valueOf(bundle.get("addrLat"));
        tvAddress.setText(String.valueOf(bundle.get("address")));
    }

    private void handleJumpBackRemark(Bundle bundle) {
        if (bundle == null) {
            return;
        }
        remark = String.valueOf(bundle.get("remark"));
        if (("").equals(remark) || ("null").equals(remark)) {
            tvRemark.setText("");
        } else {
            tvRemark.setText(remark);
        }
    }

    private void handleJumpBackVoucher() {
        /*唯一有用的，其实只是抵用券ID而已*/
        ArrayList<String> voucherIDList = SelectedVoucherIDListHelper.getInstance().getSelfVoucherList();
        if (voucherIDList != null && voucherIDList.size() == 1) {
            voucherID = voucherIDList.get(0);
        }
        voucherPrice = SelectedVoucherIDListHelper.getInstance().getTotalSelectedVoucherPrice();
        updateTotalPrice();
        String newVoucherInfo = VoucherBiz.getVoucherInfo(voucherInfo);/*选中抵用券之后，处理抵用券信息可调用此方法*/
        VoucherBiz.setVoucherInfoBackground(tvVoucherInfo, newVoucherInfo, this);
    }

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int id = v.getId();
            switch (id) {
                case R.id.tv_one:/*服务说明*/
                    jumpToIntroduction();
                    break;
                case R.id.tv_address:/*选择地址*/
                    jumpToAddress();
                    break;
                case R.id.etNote:
                    jumpToRemark();
                    break;
                case R.id.rlNormal:/*选择普通洗车*/
                    if (hasWashCarService()) {
                        selectWashCarType(0);
                      /*请求洗车规格列表成功后，请求最高金额抵用券*/
                        requestVoucherHighestPrice();
                    }
                    break;
                case R.id.rlDelicate:/*选择精致洗车*/
                    if (hasWashCarService()) {
                        selectWashCarType(1);
                        requestVoucherHighestPrice();
                    }
                    break;
                case R.id.llVoucher:/*选择抵用券*/
                    jumpToVoucherList();
                    break;
                case R.id.rlCleanInterior: /*是否清洗车内饰*/
                    selectWashInner();
                    break;
                case R.id.btPayCost:/*结算洗车费的按钮*/
                    if (hasWashCarService()) {
                        requestAddWashCarOrder();
                    }
                    break;
                case R.id.ivSwitch://是否使用积分抵扣
                    showDialog(WashCarActivity.this);
                    if (ivSwitchSelected) {
                        ivSwitchSelected = false;
                        isDeduction = 0;
                        ivSwitch.setSelected(ivSwitchSelected);
                        requestPoints(selectWash);
                    } else {
                        ivSwitchSelected = true;
                        isDeduction = 1;
                        ivSwitch.setSelected(ivSwitchSelected);
                        requestPoints(selectWash);

                    }
                    break;
            }
        }
    };

    private int selectWash;

    //获取可抵用积分
    private void requestPoints(int washCarType) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("pRuleID", mWashCarProductList.get(washCarType).getpRuleID());
        map.put("isDeduction", isDeduction);
        List<Map<String, Object>> params = new ArrayList<>();
        Map<String, Object> product = new HashMap<>();
        product.put("payPrice", mWashCarProductList.get(washCarType).getPrice());
        product.put("deduction", mWashCarProductList.get(washCarType).getDeduction());
        product.put("goodsNumber", "1");
        params.add(product);
        map.put("params", params);
        MyPointBiz.getDeduction(map, new VolleyHttpUtil.ResponseCallBack() {
            @Override
            public void handleResponse(JSONObject response, int errCode) {
                closeDialog();
                if (OrangeErrorHandler.getInstance().isSuccess(response)) {
                    handlePoints(response.toString());
                }
            }
        });
    }

    /**
     * 处理积分规则的返回数据
     *
     * @param response
     */
    private void handlePoints(String response) {
        Map<String, Object> map = JSONHelper.jsonToMap(
                response);
        if (map == null) {
            return;
        }
        Map<String, Object> entity = (Map<String, Object>) map.get("entity");
        if (entity == null) {
            return;
        }
        //  deductionPoints	可抵用积分
        //  deductionPrice	可抵用多少钱
        //  points	抵用后可以得多少积分
        deductionPrice = String.valueOf(entity.get("deductionPrice"));
        String deductionPoints = String.valueOf(entity.get("deductionPoints"));
        points = String.valueOf(entity.get("points"));
        if (!ivSwitchSelected || StringUtil.isBlank(deductionPrice)) {
            deductionPrice = "0";
        }
        zeng.setVisibility(View.VISIBLE);
        tvJifenTip.setText("橙汁" + points + "ml");
        tvPoint.setText("使用" + deductionPoints + "ml橙汁可抵扣" + deductionPrice + "金额");
        updateTotalPrice();

    }

    private String deductionPrice = "0";//积分抵用价格
    private String voucherPrice = "0";//抵用券抵用价格
    private String mCurrentGoodsPrice;//商品价格
    private String mTotalCost;//最终商品价格

    /**
     * 最后价格展示
     */
    private void updateTotalPrice() {
        if (StringUtil.isBlank(voucherPrice)) {
            voucherPrice = "0";
        }
        if (StringUtil.isBlank(deductionPrice)) {
            deductionPrice = "0";
        }
        if (StringUtil.isBlank(mCurrentGoodsPrice)) {
            mCurrentGoodsPrice = "0";
        }

        mTotalCost = DecimalUtil.subtract(mCurrentGoodsPrice, deductionPrice);
        mTotalCost = DecimalUtil.subtract(mTotalCost, voucherPrice);
        mTotalCost = MoneyUtil.handleMoney(mTotalCost);
        tvPropertyNum.setText(mTotalCost);
    }

    private boolean hasWashCarService() {
        if (!hasWashCarService) {
            ToastHelper.getInstance()._toast(msgNoService);
            return false;
        }

        return true;
    }

    private void setListener() {
        tvOne.setOnClickListener(listener);
        tvAddress.setOnClickListener(listener);
        rlNormal.setOnClickListener(listener);
        rlDelicate.setOnClickListener(listener);
        llVoucher.setOnClickListener(listener);
        rlCleanInterior.setOnClickListener(listener);
        btPayCost.setOnClickListener(listener);
        etNote.setOnClickListener(listener);
        ivSwitch.setOnClickListener(listener);
    }

    private void showProgress() {
        if (currentReqMode == NETWORK_LOADING) {
            emptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
        }
    }

    private void dismissProgress() {
        if (currentReqMode == NETWORK_LOADING) {
            emptyLayout.dismiss();
        }
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        SelectedVoucherIDListHelper.getInstance().destroyBiz();
    }
}
